<template>
  <button
    class="press-night-button"
    :class="{ 'night-mode': isNight }"
    @mousedown="switchToNight"
    @mouseup="switchToDay"
    @mouseleave="switchToDay"
    @touchstart="switchToNight"
    @touchend="switchToDay"
    @touchcancel="switchToDay"
    aria-label="按下黑夜松开白天按钮"
  >
    <div class="icon-container">
      <div class="sun-moon">
        <div class="sun"></div>
        <div class="moon">
          <div class="crater crater-1"></div>
          <div class="crater crater-2"></div>
          <div class="crater crater-3"></div>
        </div>
      </div>
    </div>
    <span class="button-text">{{ isNight ? text : text }}</span>
  </button>
</template>

<script setup>
import { ref } from 'vue';
import { defineProps, defineEmits } from 'vue';
const isNight = ref(false);
const props = defineProps({
  text: {
    type: String,
    default: '点击',
  }


});

const switchToNight = () => {
  isNight.value = true;
};

const switchToDay = () => {
  isNight.value = false;
};
</script>

<style scoped>
.press-night-button {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0.75rem 1.5rem 0.75rem 1rem;
  border-radius: 50px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  color: #000000;
  background: linear-gradient(to right, #cbf6ff, hsla(228, 93%, 59%, 0.553));
  box-shadow: 0 4px 15px rgba(255, 254, 254, 0.3);
  overflow: hidden;
  /* 平滑过渡效果 */
  transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.press-night-button.night-mode {
  background: linear-gradient(to left, #3cc2e4, #ffb300);
  color: #000000;
  box-shadow: 0 2px 8px rgba(20, 30, 48, 0.5);
  transform: translateY(2px) scale(0.98);
}

.icon-container {
  position: relative;
  width: 24px;
  height: 24px;
  margin-right: 12px;
}

.sun-moon {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

.sun {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  background: #ffcc33;
  border-radius: 50%;
  transform: scale(1);
  transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
  box-shadow: 0 0 10px rgba(255, 204, 51, 0.8);
}

.sun::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 6px;
    opacity: 1;
  transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

.moon {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  background: transparent;
  border-radius: 50%;
  transform: scale(0);
  transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

.crater {
  position: absolute;
  background: #e0e0e0;
  border-radius: 50%;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

.crater-1 {
  width: 6px;
  height: 6px;
  top: 6px;
  left: 9px;
}

.crater-2 {
  width: 4px;
  height: 4px;
  top: 14px;
  left: 6px;
}

.crater-3 {
  width: 5px;
  height: 5px;
  top: 10px;
  left: 15px;
}

/* Night mode transformations */
.night-mode .sun {
  background: #e0e0e0;
  transform: scale(0.7);
  box-shadow: 0 0 5px rgba(224, 224, 224, 0.3);
}

.night-mode .sun::before {
  opacity: 0;
}

.night-mode .moon {
  background: #e0e0e0;
  transform: scale(1) rotate(-45deg);
  box-shadow: 0 0 10px rgba(181, 181, 181, 0.626);
}

.night-mode .crater {
  opacity: 1;
}

.button-text {
  position: relative;
  z-index: 1;
  transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Hover effects */
.press-night-button:hover:not(.night-mode) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 255, 255, 0.4);
}

/* Add stars in night mode */
.night-mode::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    radial-gradient(1px 1px at 10px 10px, white 50%, transparent 100%),
    radial-gradient(1px 1px at 30px 20px, white 50%, transparent 100%),
    radial-gradient(1px 1px at 50px 15px, white 50%, transparent 100%),
    radial-gradient(1px 1px at 70px 25px, white 50%, transparent 100%),
    radial-gradient(1px 1px at 90px 10px, white 50%, transparent 100%);
  opacity: 0;
  z-index: 0;
  transition: opacity 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

.night-mode::before {
  opacity: 0.2;
  animation: twinkling 5s infinite ease-in-out;
}

@keyframes twinkling {
  0% { opacity: 0.1; }
  50% { opacity: 0.3; }
  100% { opacity: 0.1; }
}

/* 添加按压效果 */
.press-night-button::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.05);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.night-mode::after {
  opacity: 1;
}
</style>
